package com.automannn.springPractice.zStudy.lifecycle;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author weave
 * @since 2024-06-27 10:16
 */
@Slf4j
public class App {

    /*
        com.automannn.springPractice.zStudy.lifecycle.App - Init application context
        com.automannn.springPractice.zStudy.lifecycle.MyBeanFactoryPostProcessor - execute BeanFactoryPostProcessor#postProcessBeanFactory
        com.automannn.springPractice.zStudy.lifecycle.MyInstantiationAwareBeanPostProcessor - execute InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation for beansConfig
        com.automannn.springPractice.zStudy.lifecycle.MyInstantiationAwareBeanPostProcessor - execute InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation for beansConfig
        com.automannn.springPractice.zStudy.lifecycle.MyInstantiationAwareBeanPostProcessor - execute InstantiationAwareBeanPostProcessor#postProcessProperties for beansConfig
        com.automannn.springPractice.zStudy.lifecycle.MyBeanPostProcessor - execute BeanPostProcessor#postProcessBeforeInitialization for beansConfig
        com.automannn.springPractice.zStudy.lifecycle.MyBeanPostProcessor - execute BeanPostProcessor#postProcessAfterInitialization for beansConfig
        com.automannn.springPractice.zStudy.lifecycle.MyInstantiationAwareBeanPostProcessor - execute InstantiationAwareBeanPostProcessor#postProcessBeforeInstantiation for user
        com.automannn.springPractice.zStudy.lifecycle.User - execute User#new User()
        com.automannn.springPractice.zStudy.lifecycle.User - execute User#setName(weave)
        com.automannn.springPractice.zStudy.lifecycle.User - execute User#setAge(26)
        com.automannn.springPractice.zStudy.lifecycle.MyInstantiationAwareBeanPostProcessor - execute InstantiationAwareBeanPostProcessor#postProcessAfterInstantiation for user
        com.automannn.springPractice.zStudy.lifecycle.MyInstantiationAwareBeanPostProcessor - execute InstantiationAwareBeanPostProcessor#postProcessProperties for user
        com.automannn.springPractice.zStudy.lifecycle.User - execute BeanNameAware#setBeanName
        com.automannn.springPractice.zStudy.lifecycle.User - execute BeanFactoryAware#setBeanFactory
        com.automannn.springPractice.zStudy.lifecycle.User - execute ApplicationContextAware#setApplicationContext
        com.automannn.springPractice.zStudy.lifecycle.MyBeanPostProcessor - execute BeanPostProcessor#postProcessBeforeInitialization for user
        com.automannn.springPractice.zStudy.lifecycle.User - execute InitializingBean#afterPropertiesSet
        com.automannn.springPractice.zStudy.lifecycle.User - execute User#doInit
        com.automannn.springPractice.zStudy.lifecycle.MyBeanPostProcessor - execute BeanPostProcessor#postProcessAfterInitialization for user
        com.automannn.springPractice.zStudy.lifecycle.App - User(name=weave, age=26, beanFactory=org.springframework.beans.factory.support.DefaultListableBeanFactory@49c66ade: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.event.internalEventListenerProcessor,org.springframework.context.event.internalEventListenerFactory,beansConfig,myBeanFactoryPostProcessor,myBeanPostProcessor,myInstantiationAwareBeanPostProcessor,user]; root of factory hierarchy, applicationContext=org.springframework.context.annotation.AnnotationConfigApplicationContext@50313382, started on Thu Jun 27 10:22:32 CST 2024, beanName=user)
        com.automannn.springPractice.zStudy.lifecycle.App - Shutdown application context
        com.automannn.springPractice.zStudy.lifecycle.User - execute DisposableBean#destroy
        com.automannn.springPractice.zStudy.lifecycle.User - execute User#doDestroy
    */
    public static void main(String[] args) {
        log.info("Init application context");
        // create and configure beans
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
                "com.automannn.springPractice.zStudy.lifecycle");

        // retrieve configured instance
        User user = (User) context.getBean("user");

        // print info from beans
        log.info(user.toString());

        log.info("Shutdown application context");
        context.registerShutdownHook();
    }
}
